package com.cml.client.domain.service;

import com.cml.common.dto.entity.ServiceInstance;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 姓名：陈茂林
 * 时间：2023/11/16 8:18
 * 描述：
 */
public class CacheRegisterServiceInstance {
    private ConcurrentHashMap<String, List> serviceInstanceCache = new ConcurrentHashMap<>();
    private static class Singleton{
        private static CacheRegisterServiceInstance cacheRegisterServiceInstance
                =new CacheRegisterServiceInstance();
    }

    public static CacheRegisterServiceInstance getInstance(){
        return Singleton.cacheRegisterServiceInstance;
    }

    public   void serviceInstanceCache(ServiceInstance serviceInstance){
        List serviceRegisterOnlineList = this.serviceInstanceCache.get(serviceInstance.getServiceName());
        if(serviceRegisterOnlineList== null){
            serviceRegisterOnlineList=new ArrayList();
            this.serviceInstanceCache.put(serviceInstance.getServiceName(),serviceRegisterOnlineList);
        }
        serviceRegisterOnlineList.add(serviceInstance);
    }

    public List<ServiceInstance> getServiceInstanceList(String serviceName){
        return serviceInstanceCache.get(serviceName);
    }
}
